#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <sys/un.h>
#include <string.h>
#include <netdb.h>
#include <netinet/in.h>

#define HOST_IP	"127.0.0.1"
#define HOST_NAME	"127.0.0.1"

int main(int argc, char *argv[])
{
	int s_fd;
	struct sockaddr_in s_addr;
	struct hostent	*s_env;
	char buf[100];
	
	// 1. create socket
	s_fd = socket(AF_INET, SOCK_STREAM, 0);
	if(s_fd == -1){ perror("sock failed"); exit(-1);}
	// 2. connet
	s_addr.sin_family = AF_INET;
	s_addr.sin_port = htons(8080);
	//if(inet_aton(HOST_IP, &(s_addr.sin_addr)) == -1){ perror("ip failed"); exit(-1);}
	s_env = gethostbyname(HOST_NAME);
	if(s_env == NULL){ perror("get host failed"); exit(-1);}
	s_addr.sin_addr = *((struct in_addr *)s_env->h_addr);
	if(connect(s_fd, (struct sockaddr *)&s_addr, sizeof(s_addr)) == -1){
		perror("connect failed");
		exit(-1);
	}
	// 3. read msg
	//read(s_fd, buf, 100);
	recv(s_fd, buf, 100, 0);
	printf("get msg : %s\n",buf);
	// 4. close
	close(s_fd);

	return 0;
}
